package Collection.map;

import java.util.*;

public class MapIterator {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("key1", "value1");
        map.put("key2", "value2");
        map.put("key3", "value3");

        //1. 遍历map的key
        map.keySet().forEach(System.out::println);
        Set<String> keys = map.keySet();
        for(String key : keys){
            System.out.println(map.get(key));
        }
        Iterator iterator1 = keys.iterator();
        while(iterator1.hasNext()){
            String key = (String) iterator1.next();
            System.out.println(map.get(key));
        }

        //2.Values
        map.values().forEach(System.out::println);
        Collection<String> values = map.values();
        for(String value : values){
            System.out.println(value);
        }
       Iterator<String> iterator2 =  values.iterator();
        while(iterator2.hasNext()){
            String value = iterator2.next();
            System.out.println(value);
        }

        //3.entrySet
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for(Map.Entry<String, String> entry : entries){
            System.out.println(entry.getKey() + " = " + entry.getValue());
        }
        Iterator<Map.Entry<String, String>> iterator3 = entries.iterator();
        while(iterator3.hasNext()){
            Map.Entry<String, String> entry = iterator3.next();
            System.out.println(entry.getKey() + " = " + entry.getValue());
        }

    }
}

